﻿using GalaSoft.MvvmLight.Messaging;
using PPP.Model;
using PPP.ViewModel.BaseModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;

namespace PPP.ViewModel.WindowModel {
    /// <summary>
    /// ViewModel for a picture preview. 
    /// 
    /// <list type="bullet">
    /// <item>
    /// <term>Author</term>
    /// <description>Sebastian Will</description>
    /// </item>
    /// </list>
    /// 
    /// </summary>
    public class PreviewViewModel : ToolViewModel {
        
        #region Fields

        /// <summary>
        /// The selected picture.
        /// </summary>
        private PicturePropertiesViewModel _selectedPicture = null;        
        
        #endregion

        #region Consts

        /// <summary>
        /// The dockable content content id.
        /// </summary>
        public const string ToolContentId = "PreviewTool";

        #region PropertyName Consts

        /// <summary>
        /// The <see cref="SelectedPicture" /> property's name.
        /// </summary>
        public const string SelectedPicturePropertyName = "SelectedPicture";
        #endregion
        
        #endregion        

        #region Properties
        #region Commands
        #endregion

        /// <summary>
        /// Gets the SelectedPicture property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public PicturePropertiesViewModel SelectedPicture {
            get {
                return _selectedPicture;
            }
            set {
                if (_selectedPicture == value)
                    return;

                _selectedPicture = value;
                RaisePropertyChanged(SelectedPicturePropertyName);

            }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the PreviewViewModel class.
        /// </summary>  
        public PreviewViewModel()
            : base(Properties.ResourcesPaneTitle.PicturePreviewPane) {
            //MainViewModel.This.ActiveDocumentChanged += new EventHandler(OnActiveDocumentChanged);
            ContentId = ToolContentId;

            BitmapImage bi = new BitmapImage();
            bi.BeginInit();
            bi.UriSource = new Uri("pack://application:,,,/PPP;component/icons/gui/picturePreview.png");
            bi.EndInit();
            IconSource = bi;

            Messenger.Default.Register<PropertyChangedMessage<PicturePropertiesViewModel>>(
                this,
                message => {
                    SelectedPicture = null;
                    SelectedPicture = message.NewValue;
                });
        }

        #endregion

        #region Methods
        #endregion

        #region Events
        #endregion
    }
}
